import getIn from './getIn';
/**
 * 解码url参数，url原始参数形式为parameter=(list_c2087d74%23row:11%24page:10)1#row:1$page:0|2#row:1$page:0,
 * 符号规定：|分割组件， #分割组件参数和组件id， $分割参数， :分割值
 * 转码后变成{1:{row: 1, page:0}}
 * @param paramsString
 */
export default function decodeParams(paramsString) {
    let params;
    if (paramsString) {
        paramsString = decodeURIComponent(paramsString)
        params = {};
        const components = paramsString.split('|');// 组件列表, ['1#row:1$page:0','2#row:1$page:0']
        components && components.forEach((c) => {
            const d = c.split('#');// 参数列表,['id:1', 'row:1']
            if (d && d.length === 2) {
                const componentId = d[0];
                params[componentId] = {};
                const cps = d[1].split('$');
                cps && cps.forEach((cp) => {
                    const p = cp.split(':');// 参数键值对
                    params[componentId][getIn(p, [0])] = getIn(p, [1]);
                });
            }
        });
    }
    return params;
}
